package org.example.sb_api.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.sb_api.common.Result;
import org.example.sb_api.dto.LoginDTO;
import org.example.sb_api.dto.RegisterDTO;
import org.example.sb_api.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "用户管理")
@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation("手机号登录")
    @PostMapping("/phoneLogin")
    public Result phoneLogin(@RequestBody LoginDTO loginDTO) {
        return userService.phoneLogin(loginDTO);
    }

    @ApiOperation("用户注册")
    @PostMapping("/register")
    public Result register(@RequestBody RegisterDTO registerDTO) {
        return userService.register(registerDTO);
    }

    @ApiOperation("用户名密码登录")
    @PostMapping("/login")
    public Result login(@RequestBody LoginDTO loginDTO) {
        return userService.login(loginDTO);
    }

    @ApiOperation("获取验证码")
    @GetMapping("/getVerificationCode")
    public Result getVerificationCode(@RequestParam String phone) {
        return userService.getVerificationCode(phone);
    }
} 